package com.lightheart.sphr.xiaobinggan.customchannel

import android.util.Log
import com.blankj.utilcode.util.ToastUtils
import com.cheng.channel.Channel
import com.cheng.channel.ChannelView
import com.cheng.channel.ChannelView.OnChannelListener
import com.lightheart.sphr.xiaobinggan.R
import com.lightheart.sphr.xiaobinggan.base.BaseActivity
import com.lightheart.sphr.xiaobinggan.module.home.presenter.HomePresenter
import com.lightheart.sphr.xiaobinggan.timeselection.uitls.CustomToastUtils
import kotlinx.android.synthetic.main.activity_channel_view.*
import kotlinx.android.synthetic.main.common_toolbar.*
import java.util.*

class ChannelViewActivity : BaseActivity<HomePresenter>(), OnChannelListener {

    private val TAG = javaClass.simpleName


    override fun getLayoutId() = R.layout.activity_channel_view

    override fun initInjector() {
    }

    override fun initView() {
        initToolbar(common_toolbar, common_toolbar_title_tv, bt_sub, R.string.channel_view, false, R.string.register)

        val myChannel = arrayOf("要闻", "视频", "新时代", "娱乐", "体育", "军事", "NBA", "国际", "科技", "财经", "汽车", "电影", "游戏", "独家", "房产",
                "图片", "时尚", "呼和浩特", "三打白骨精")
        val recommendChannel1 = arrayOf("综艺", "美食", "育儿", "冰雪", "必读", "政法网事", "都市",
                "NFL", "韩流")
        val recommendChannel2 = arrayOf("问答", "文化", "佛学", "股票", "动漫", "理财", "情感", "职场", "旅游")
        val recommendChannel3 = arrayOf("家居", "电竞", "数码", "星座", "教育", "美容", "电视剧",
                "搏击", "健康")
        val myChannelList: MutableList<Channel> = ArrayList()
        val recommendChannelList1: MutableList<Channel> = ArrayList()
        val recommendChannelList2: MutableList<Channel> = ArrayList()
        val recommendChannelList3: MutableList<Channel> = ArrayList()
        for (i in myChannel.indices) {
            val aMyChannel = myChannel[i]
            var channel: Channel
            channel = if (i > 2 && i < 6) {
                //可设置频道归属板块（channelBelong），当前设置此频道归属于第二板块，当删除该频道时该频道将回到第二板块
                Channel(aMyChannel, 2, i)
            } else if (i > 7 && i < 10) {
                //可设置频道归属板块（channelBelong），当前设置此频道归属于第三板块，当删除该频道时该频道将回到第三板块中
                Channel(aMyChannel, 3, i)
            } else {
                Channel(aMyChannel, i as Any)
            }
            myChannelList.add(channel)
        }
        for (aMyChannel in recommendChannel1) {
            val channel = Channel(aMyChannel)
            recommendChannelList1.add(channel)
        }
        for (aMyChannel in recommendChannel2) {
            val channel = Channel(aMyChannel)
            recommendChannelList2.add(channel)
        }
        for (aMyChannel in recommendChannel3) {
            val channel = Channel(aMyChannel)
            recommendChannelList3.add(channel)
        }
        channelView.setChannelFixedCount(3)
        channelView.addPlate("我的频道", myChannelList)
        channelView.addPlate("推荐频道", recommendChannelList1)
        channelView.addPlate("国内", recommendChannelList2)
        channelView.addPlate("国外", recommendChannelList3)
        channelView.inflateData()
        channelView.setChannelNormalBackground(R.drawable.bg_channel_normal)
        channelView.setChannelEditBackground(R.drawable.bg_channel_edit)
        channelView.setChannelFocusedBackground(R.drawable.bg_channel_focused)
        channelView.setOnChannelItemClickListener(this)
    }

    override fun channelEditStart() {
        CustomToastUtils.imgToast("2","6666")
    }

    override fun channelItemClick(position: Int, channel: Channel?) {
        Log.i(TAG, "$position..$channel")
        CustomToastUtils.imgToast("item$position$channel","666")
    }

    override fun channelEditFinish(channelList: MutableList<Channel>?) {
        Log.i(TAG, channelList.toString())
        Log.i(TAG, channelView.myChannel.toString())
    }
}